﻿using System;
using System.Windows.Data;

namespace Coevery.PhoneApp.Convert
{
    public class StringConverter : IValueConverter   
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var str = System.Convert.ToString(value);
            var length = 0;
            foreach (var item in str)
            {
                if (char.IsUpper(item))
                {
                    length++;
                }
            }
            if (str.Length > (30 - (length*0.25)))
            {
                str = string.Format("{0}...", str.Substring(0, 30 - (int)(length * 0.25)));
            }
            return str;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Convert(value, targetType, parameter, culture);
        }
    }
}
